<script setup>
import { ref } from 'vue'
import { VideoPlay, Clock, CircleCheck, Warning, Delete } from '@element-plus/icons-vue'

// 模拟数据
const activeTab = ref('published')
const videos = ref({
  published: [
    { id: 1, title: '夏日海滩之旅', views: '12.4万', likes: '8.2万', status: 'published', cover: 'https://dummyimage.com/300x500/4a86e8/fff' },
    { id: 2, title: '猫咪的搞笑日常', views: '28.7万', likes: '15.3万', status: 'published', cover: 'https://dummyimage.com/300x500/6aa84f/fff' }
  ],
  reviewing: [
    { id: 3, title: '美食探店vlog', views: '0', likes: '0', status: 'reviewing', cover: 'https://dummyimage.com/300x500/e69138/fff' },
    { id: 4, title: '舞蹈挑战', views: '0', likes: '0', status: 'reviewing', cover: 'https://dummyimage.com/300x500/ff00ff/fff' }
  ],
  rejected: [
    { id: 5, title: '极限运动集锦', views: '0', likes: '0', status: 'rejected', reason: '包含危险动作', cover: 'https://dummyimage.com/300x500/cc0000/fff' },
    { id: 6, title: '音乐翻唱', views: '0', likes: '0', status: 'rejected', reason: '版权问题', cover: 'https://dummyimage.com/300x500/ff9999/fff' }
  ]
})

// 状态标签配置
const statusConfig = {
  published: { text: '已发布', type: 'success', icon: CircleCheck },
  reviewing: { text: '审核中', type: 'warning', icon: Clock },
  rejected: { text: '未通过', type: 'danger', icon: Warning }
}

// 操作处理函数
const handleDelete = (id) => {
  Object.keys(videos.value).forEach(status => {
    videos.value[status] = videos.value[status].filter(video => video.id !== id)
  })
}
</script>

<template>
  <div class="video-manager-container">
    <!-- 顶部标题 -->
    <div class="header">
      <h1>内容管理</h1>
      <p>管理您上传的所有视频内容</p>
    </div>

    <!-- Tab导航 -->
    <el-tabs v-model="activeTab" class="tabs" stretch>
      <el-tab-pane name="published">
        <template #label>
          <span class="tab-label">
            <el-icon><VideoPlay /></el-icon>
            <span>已发布</span>
          </span>
        </template>
      </el-tab-pane>
      
      <el-tab-pane name="reviewing">
        <template #label>
          <span class="tab-label">
            <el-icon><Clock /></el-icon>
            <span>审核中</span>
          </span>
        </template>
      </el-tab-pane>
      
      <el-tab-pane name="rejected">
        <template #label>
          <span class="tab-label">
            <el-icon><Warning /></el-icon>
            <span>未通过</span>
          </span>
        </template>
      </el-tab-pane>
    </el-tabs>

    <!-- 视频列表 -->
    <div class="video-list">
      <div 
        v-for="video in videos[activeTab]" 
        :key="video.id" 
        class="video-card"
      >
        <!-- 视频封面 -->
        <div class="video-cover" :style="{ backgroundImage: `url(${video.cover})` }">
          <div class="status-badge">
            <el-tag :type="statusConfig[video.status].type" size="small">
              <el-icon class="icon"><component :is="statusConfig[video.status].icon" /></el-icon>
              {{ statusConfig[video.status].text }}
            </el-tag>
          </div>
        </div>
        
        <!-- 视频信息 -->
        <div class="video-info">
          <h3 class="title">{{ video.title }}</h3>
          
          <div class="stats">
            <span>播放: {{ video.views }}</span>
            <span>点赞: {{ video.likes }}</span>
          </div>
          
          <!-- 拒绝原因 -->
          <div v-if="video.reason" class="rejection-reason">
            <el-alert :title="`未通过原因: ${video.reason}`" type="error" show-icon :closable="false" />
          </div>
          
          <!-- 操作按钮 -->
          <div class="actions">
            <el-button type="primary" size="small">编辑</el-button>
            <el-button 
              type="danger" 
              size="small" 
              @click="handleDelete(video.id)"
            >
              <el-icon><Delete /></el-icon>
              删除
            </el-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.video-manager-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
  
  .header {
    margin-bottom: 30px;
    
    h1 {
      font-size: 28px;
      font-weight: 600;
      color: #1a1a1a;
      margin-bottom: 8px;
    }
    
    p {
      font-size: 14px;
      color: #666;
    }
  }
  
  .tabs {
    margin-bottom: 25px;
    
    :deep(.el-tabs__item) {
      font-size: 16px;
      padding: 0 20px;
      height: 50px;
    }
    
    .tab-label {
      display: flex;
      align-items: center;
      gap: 8px;
    }
  }
  
  .video-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
  }
  
  .video-card {
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    
    &:hover {
      transform: translateY(-5px);
      box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
    }
  }
  
  .video-cover {
    position: relative;
    height: 180px;
    background-size: cover;
    background-position: center;
    
    .status-badge {
      position: absolute;
      top: 12px;
      right: 12px;
      
      .icon {
        margin-right: 4px;
      }
    }
  }
  
  .video-info {
    padding: 16px;
    
    .title {
      font-size: 16px;
      font-weight: 500;
      margin-bottom: 12px;
      color: #333;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
    
    .stats {
      display: flex;
      gap: 15px;
      font-size: 13px;
      color: #909399;
      margin-bottom: 12px;
    }
    
    .rejection-reason {
      margin: 12px 0;
      
      :deep(.el-alert) {
        padding: 6px 12px;
      }
    }
    
    .actions {
      display: flex;
      gap: 10px;
      margin-top: 15px;
    }
  }
}
</style>